package com.example.dyxeapplication.content.menu.alfabet.ear;

import com.example.dyxeapplication.R;
import com.example.dyxeapplication.content.menu.alfabet.Alfabet;
import com.example.dyxeapplication.content.menu.alfabet.eye.Eye;
import com.example.dyxeapplication.content.menu.alfabet.hand.Hands;
import com.example.dyxeapplication.content.menu.alfabet.lips.Lips;
import com.example.dyxeapplication.menu.Menu;
import com.example.dyxeapplication.setting.temp;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class Ear extends Activity {
	private Button buttonPlay;
	private MediaPlayer mp;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ear);
		Button eye = (Button) findViewById(R.id.iconeye);
		Button hand = (Button) findViewById(R.id.iconhand);
		Button ear = (Button) findViewById(R.id.iconear);
		Button lips = (Button) findViewById(R.id.iconlips);
		
		ImageView imgview1 = (ImageView) findViewById(R.id.recEarBesar);
		ImageView imgview2 = (ImageView) findViewById(R.id.recEarKecil);
		
		buttonPlay = (Button) findViewById(R.id.ButtonPlayStop);
		
		if (mp != null)
			mp.release();

		if (temp.huruf.equals("a")) {
			imgview1.setImageResource(R.drawable.abesar);
			imgview2.setImageResource(R.drawable.akecil);
			mp = MediaPlayer.create(this, R.raw.a);
			
		} else if (temp.huruf.equals("b")) {
			imgview1.setImageResource(R.drawable.bbesar);
			imgview2.setImageResource(R.drawable.bkecil);
			mp = MediaPlayer.create(this, R.raw.b);

		}else if (temp.huruf.equals("c")) {
			imgview1.setImageResource(R.drawable.cbesar);
			imgview2.setImageResource(R.drawable.ckecil);
			mp = MediaPlayer.create(this, R.raw.c);

		}else if (temp.huruf.equals("d")) {
			imgview1.setImageResource(R.drawable.dbesar);
			imgview2.setImageResource(R.drawable.dkecil);
			mp = MediaPlayer.create(this, R.raw.d);

		}else if (temp.huruf.equals("e")) {
			imgview1.setImageResource(R.drawable.ebesar);
			imgview2.setImageResource(R.drawable.ekecil);
			mp = MediaPlayer.create(this, R.raw.e);

		}else if (temp.huruf.equals("f")) {
			imgview1.setImageResource(R.drawable.fbesar);
			imgview2.setImageResource(R.drawable.fkecil);
			mp = MediaPlayer.create(this, R.raw.f);

		}else if (temp.huruf.equals("g")) {
			imgview1.setImageResource(R.drawable.gbesar);
			imgview2.setImageResource(R.drawable.gkecil);
			mp = MediaPlayer.create(this, R.raw.g);

		}else if (temp.huruf.equals("h")) {
			imgview1.setImageResource(R.drawable.hbesar);
			imgview2.setImageResource(R.drawable.hkecil);
			mp = MediaPlayer.create(this, R.raw.h);

		}else if (temp.huruf.equals("i")) {
			imgview1.setImageResource(R.drawable.ibesar);
			imgview2.setImageResource(R.drawable.ikecil);
			mp = MediaPlayer.create(this, R.raw.i);

		}else if (temp.huruf.equals("j")) {
			imgview1.setImageResource(R.drawable.jbesar);
			imgview2.setImageResource(R.drawable.jkecil);
			mp = MediaPlayer.create(this, R.raw.j);

		}else if (temp.huruf.equals("k")) {
			imgview1.setImageResource(R.drawable.kbesar);
			imgview2.setImageResource(R.drawable.kkecil);
			mp = MediaPlayer.create(this, R.raw.k);

		}else if (temp.huruf.equals("l")) {
			imgview1.setImageResource(R.drawable.lbesar);
			imgview2.setImageResource(R.drawable.lkecil);
			mp = MediaPlayer.create(this, R.raw.l);

		}else if (temp.huruf.equals("m")) {
			imgview1.setImageResource(R.drawable.mbesar);
			imgview2.setImageResource(R.drawable.mkecil);
			mp = MediaPlayer.create(this, R.raw.m);

		}else if (temp.huruf.equals("n")) {
			imgview1.setImageResource(R.drawable.nbesar);
			imgview2.setImageResource(R.drawable.nkecil);
			mp = MediaPlayer.create(this, R.raw.n);

		}else if (temp.huruf.equals("o")) {
			imgview1.setImageResource(R.drawable.obesar);
			imgview2.setImageResource(R.drawable.okecil);
			mp = MediaPlayer.create(this, R.raw.o);

		}else if (temp.huruf.equals("p")) {
			imgview1.setImageResource(R.drawable.pbesar);
			imgview2.setImageResource(R.drawable.pkecil);
			mp = MediaPlayer.create(this, R.raw.p);

		}else if (temp.huruf.equals("q")) {
			imgview1.setImageResource(R.drawable.qbesar);
			imgview2.setImageResource(R.drawable.qkecil);
			mp = MediaPlayer.create(this, R.raw.q);

		}else if (temp.huruf.equals("r")) {
			imgview1.setImageResource(R.drawable.rbesar);
			imgview2.setImageResource(R.drawable.rkecil);
			mp = MediaPlayer.create(this, R.raw.r);

		}else if (temp.huruf.equals("s")) {
			imgview1.setImageResource(R.drawable.sbesar);
			imgview2.setImageResource(R.drawable.skecil);
			mp = MediaPlayer.create(this, R.raw.s);

		}else if (temp.huruf.equals("t")) {
			imgview1.setImageResource(R.drawable.tbesar);
			imgview2.setImageResource(R.drawable.tkecil);
			mp = MediaPlayer.create(this, R.raw.t);

		}else if (temp.huruf.equals("u")) {
			imgview1.setImageResource(R.drawable.ubesar);
			imgview2.setImageResource(R.drawable.ukecil);
			mp = MediaPlayer.create(this, R.raw.u);

		}else if (temp.huruf.equals("v")) {
			imgview1.setImageResource(R.drawable.vbesar);
			imgview2.setImageResource(R.drawable.vkecil);
			mp = MediaPlayer.create(this, R.raw.v);

		}else if (temp.huruf.equals("w")) {
			imgview1.setImageResource(R.drawable.wbesar);
			imgview2.setImageResource(R.drawable.wkecil);
			mp = MediaPlayer.create(this, R.raw.w);

		}else if (temp.huruf.equals("x")) {
			imgview1.setImageResource(R.drawable.xbesar);
			imgview2.setImageResource(R.drawable.xkecil);
			mp = MediaPlayer.create(this, R.raw.x);

		}else if (temp.huruf.equals("y")) {
			imgview1.setImageResource(R.drawable.ybesar);
			imgview2.setImageResource(R.drawable.ykecil);
			mp = MediaPlayer.create(this, R.raw.y);

		}else if (temp.huruf.equals("z")) {
//			Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.zbesar);
//		    imgview1.setImageBitmap(bMap);
//		    Bitmap bMap2 = BitmapFactory.decodeResource(getResources(), R.drawable.zkecil);
//		    imgview2.setImageBitmap(bMap2);
			imgview1.setImageResource(R.drawable.zbesar);
			imgview2.setImageResource(R.drawable.zkecil);
			mp = MediaPlayer.create(this, R.raw.z);

		}
		
		eye.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ear.this, Eye.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});
		
		hand.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ear.this, Hands.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});
		
		ear.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ear.this, Ear.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});
		
		lips.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i = new Intent(Ear.this, Lips.class);
				i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
			}
		});
		
		buttonPlay.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				mp.seekTo(0);
				mp.start();
			}
			
		});
		
	}
	

	@Override
	public void onPause() {
		super.onPause();
		// Release the MediaPlayer if going into background
		if (mp != null)
			mp.release();
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		// Release the MediaPlayer if going into background
		if (mp != null)
			mp.release();
	}
	
	@Override
	public void onBackPressed() {
		Intent myIntent = new Intent(this, Alfabet.class);
		myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(myIntent);
	}
	
	public void home(View v){
		Intent myIntent = new Intent(this, Menu.class);
		myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(myIntent);
	}
}